from datetime import datetime, timezone, timedelta
import pytz

def utc_to_local(utc_time_str, local_tz_name='Asia/Shanghai'):
    """
    Convert a UTC time string to local time.

    :param utc_time_str: The UTC time string in the format '%Y-%m-%d %H:%M:%S%z'.
    :param local_tz_name: The name of the local timezone (default is 'Asia/Shanghai').
    :return: The local time as a string in the format '%Y-%m-%d %H:%M:%S%z'.
    """
    utc_time = datetime.strptime(utc_time_str, '%Y-%m-%d %H:%M:%S')
    local_tz = pytz.timezone(local_tz_name)
    local_time = utc_time.replace(tzinfo=timezone.utc).astimezone(local_tz)
    return local_time.strftime('%Y-%m-%d %H:%M:%S')
def local_to_utc(local_time_str, local_tz_name='Asia/Shanghai'):
    """
    Convert a local time string to UTC time.

    :param local_time_str: The local time string in the format '%Y-%m-%d %H:%M:%S'.
    :param local_tz_name: The name of the local timezone (default is 'Asia/Shanghai').
    :return: The UTC time as a string in the format '%Y-%m-%d %H:%M:%S%z'.
    """
    local_tz = pytz.timezone(local_tz_name)
    local_time = datetime.strptime(local_time_str, '%Y-%m-%d %H:%M:%S')
    local_time = local_tz.localize(local_time)
    utc_time = local_time.astimezone(timezone.utc)
    return utc_time.strftime('%Y-%m-%d %H:%M:%S')

def local_to_utc1(local_time_str, local_tz_name='Asia/Shanghai'):
    """
    Convert a local time string to UTC time.

    :param local_time_str: The local time string in the format '%Y-%m-%d %H:%M:%S'.
    :param local_tz_name: The name of the local timezone (default is 'Asia/Shanghai').
    :return: The UTC time as a string in the format '%Y-%m-%d %H:%M:%S%z'.
    """
    local_tz = pytz.timezone(local_tz_name)
    local_time = datetime.strptime(local_time_str, '%Y/%m/%d %H:%M:%S')
    local_time = local_tz.localize(local_time)
    utc_time = local_time.astimezone(timezone.utc)
    return utc_time.strftime('%Y-%m-%d %H:%M:%S')
